package com.ruoyi.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.user.domain.CustomerConfig;
import com.ruoyi.user.domain.User;
import com.ruoyi.user.mapper.CustomerConfigMapper;
import com.ruoyi.user.mapper.UserMapper;
import com.ruoyi.user.service.ICustomerConfigService;

/**
 * 客服设置Service业务层处理
 * 
 * @author DEREK
 * @date 2024-10-15
 */
@Service
public class CustomerConfigServiceImpl extends ServiceImpl<CustomerConfigMapper, CustomerConfig> implements ICustomerConfigService 
{
    @Autowired
    private CustomerConfigMapper customerConfigMapper;
    @Autowired
    private UserMapper userMapper;

    /**
     * 查询客服设置
     * 
     * @param id 客服设置主键
     * @return 客服设置
     */
    @Override
    public CustomerConfig selectCustomerConfigById(Long id)
    {
        return customerConfigMapper.selectCustomerConfigById(id);
    }

    /**
     * 查询客服设置列表
     * 
     * @param customerConfig 客服设置
     * @return 客服设置
     */
    @Override
    public List<CustomerConfig> selectCustomerConfigList(CustomerConfig customerConfig)
    {
        return customerConfigMapper.selectCustomerConfigList(customerConfig);
    }

    /**
     * 新增客服设置
     * 
     * @param customerConfig 客服设置
     * @return 结果
     */
    @Override
    public int insertCustomerConfig(CustomerConfig customerConfig)
    {
        customerConfig.setCreateTime(DateUtils.getNowDate());
        return customerConfigMapper.insertCustomerConfig(customerConfig);
    }

    /**
     * 修改客服设置
     * 
     * @param customerConfig 客服设置
     * @return 结果
     */
    @Override
    public int updateCustomerConfig(CustomerConfig customerConfig)
    {
        customerConfig.setUpdateTime(DateUtils.getNowDate());
        return customerConfigMapper.updateCustomerConfig(customerConfig);
    }

    /**
     * 批量删除客服设置
     * 
     * @param ids 需要删除的客服设置主键
     * @return 结果
     */
    @Override
    public int deleteCustomerConfigByIds(Long[] ids)
    {
    	
    	CustomerConfig selectById = customerConfigMapper.selectById(ids[0]);
    	if(null != selectById) {
    		User user = new User();
        	user.setId(selectById.getUserId());
        	user.setIsCustomer(0);
        	userMapper.updateById(user);
    	}
        return customerConfigMapper.deleteCustomerConfigByIds(ids);
    }

    /**
     * 删除客服设置信息
     * 
     * @param id 客服设置主键
     * @return 结果
     */
    @Override
    public int deleteCustomerConfigById(Long id)
    {
        return customerConfigMapper.deleteCustomerConfigById(id);
    }
}
